/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author spthanh
 */
public class UpdateRow_Example {
    public static void main(String[] args){
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks", "sa", "123");

            String query = "SELECT * FROM Sales.Store WHERE [Name] LIKE 'O%'";
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

            ResultSet rs = stmt.executeQuery(query);

            //Move to first row for cusor
            rs.first();

            //Update data n-order column in the first row
            rs.updateString("Name", "Obtain - Thanh Son");

            //Commit the row updation
            rs.updateRow();

        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
